package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	fmt.Println(processLetter("mimiol"))
	println(StrToCase("miaomiaole", processLetter))

	arr := []float64{1, 2, 3, 3, 33, 3, 4, 5}

	slpit := FilterSlpit(arr, func(f float64) string {
		sqrt := math.Sqrt(f)
		return fmt.Sprintf("%.0f", sqrt)
	})

	fmt.Println(slpit)
}

type myFunc1 func(float64) string

//变量切片  对元素运算中处理
func FilterSlpit(arr []float64, f myFunc1) []string {
	var result []string
	for _, value := range arr {
		result = append(result, f(value))
	}
	return result
}

func processLetter(str string) string {
	result := ""
	for i, value := range str {
		if i%2 == 0 {
			result += strings.ToUpper(string(value))
		} else {
			result += strings.ToLower(string(value))
		}
	}
	return result
}

/**
  函数作为参数变量
*/
func StrToCase(str string, myfunc func(string) string) string {
	return myfunc(str)
}

type caseFunc func(string) string
type myfunc func(int) bool

func isEven(num int) bool {
	if num%2 == 0 {
		return true
	} else {
		return false
	}
}
func isOdd(num int) bool {
	if num%2 == 0 {
		return false
	} else {
		return true
	}
}

func isFunc(arr []int, fu myfunc) []int {
	var result []int
	for _, i2 := range arr {
		if fu(i2) {
			result = append(result, i2)
		}
	}
	return result
}

func StrToCase2(str string, func2 caseFunc) string {
	return func2(str)
}
